Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
make-error-cause
Advanced tools
The make-error-cause npm package is designed to simplify the creation of custom error classes in JavaScript, while also allowing you to maintain the original error cause. This is particularly useful for error handling in complex applications where you need to preserve the stack trace and context of the original error.
Creating Custom Error Classes
This feature allows you to create custom error classes that can encapsulate an original error. The custom error class extends from `makeErrorCause.BaseError`, which helps in maintaining the original error's stack trace and context.
const makeErrorCause = require('make-error-cause');
class MyCustomError extends makeErrorCause.BaseError {
constructor(message, cause) {
super(message, cause);
this.name = 'MyCustomError';
}
}
try {
throw new Error('Original error');
} catch (err) {
throw new MyCustomError('Custom error message', err);
}
Preserving Original Error Cause
This feature demonstrates how to preserve the original error cause when throwing a new custom error. This is useful for debugging and logging, as it provides a complete error stack trace.
const makeErrorCause = require('make-error-cause');
class DatabaseError extends makeErrorCause.BaseError {
constructor(message, cause) {
super(message, cause);
this.name = 'DatabaseError';
}
}
try {
throw new Error('Connection failed');
} catch (err) {
throw new DatabaseError('Database operation failed', err);
}
The `verror` package provides a way to create and manage nested errors in JavaScript. It allows you to add context to errors and maintain the original error stack. Compared to `make-error-cause`, `verror` offers more features for error wrapping and context management.
The `error-ex` package is used to create easily extensible error objects with additional properties. It allows you to add custom properties to errors and maintain the original error cause. While `error-ex` focuses on extensibility, `make-error-cause` is more focused on preserving the original error stack.
The `extendable-error` package provides a simple way to create custom error classes that extend the native Error class. It does not specifically focus on preserving the original error cause, making `make-error-cause` a better choice for scenarios where maintaining the original error context is crucial.
Make your own nested error types!
instanceof
error.stack
and error.name
toString
npm install make-error-cause --save
Usages from make-error
. The only difference is that errors accept a second argument known as the error "cause". The cause is used to wrap original errors with more intuitive feedback - for instance, wrapping a raw database error in a HTTP error.
const CustomError = makeErrorCause('CustomError')
const cause = new Error('boom!')
const error = new CustomError('something bad', cause)
error.toString() //=> "CustomError: something bad\nCaused by: boom!"
error.stack // Works!
error.cause.stack // Handy!
Inspired by verror
, and others, but created lighter and without core dependencies for browser usage.
Apache 2.0
FAQs
Make your own nested error types!
The npm package make-error-cause receives a total of 166,543 weekly downloads. As such, make-error-cause popularity was classified as popular.
We found that make-error-cause demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.